home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / BSCRIERR.C < prev    next >
C/C++ Source or Header  |  1993-09-10  |  6KB  |  186 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    bscrierr.c
  5. //   Title:    Base library
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //
  24. //    This module contains a critical error handler for DOS. This critical error 
  25. //    handler does not query the user for a response. 
  26. //
  27. //    The code in this module should be written entirely in C. 
  28. //    Do not use any C++ constructs.
  29. //
  30. //    This module is portable to:
  31. //        DOS 3.X+
  32. //        MS Windows 3.X+
  33. //        OS/2 2.X+
  34. //        OS/2 2.0 PM
  35. //        SCO UNIX.
  36. //
  37. //    The following compilers are supported:
  38. //        MSC 6.0A
  39. //        MSC/C++ 7.0
  40. //        Borland C++ 3.1 for DOS
  41. //        Borland C++ 1.0 for OS/2 2.X
  42. //        SCO UNIX cc
  43. //
  44. //----------------------------------------------------------------------------
  45. #include <bs.h>
  46.  
  47.  
  48. //----------------------------------------------------------------------------
  49. // Globals
  50. //----------------------------------------------------------------------------
  51. static USHORT usError = 0;
  52.  
  53.  
  54. #if OS_DOS && COMPILER_BORLAND
  55.  
  56. //----------------------------------------------------------------------------
  57. //    Globals
  58. //----------------------------------------------------------------------------
  59. static void _interrupt (*oldint24)(void);
  60.  
  61.  
  62. //----------------------------------------------------------------------------
  63. //   Description:    Critical error handler.
  64. //    Parameters:
  65. //       Returns:
  66. //----------------------------------------------------------------------------
  67. void _CDECL_ _FAR_ CritErrHandler(unsigned deverr, unsigned errval, unsigned _FAR_ *devhdr)
  68. {
  69.     NOTUSED(devhdr);
  70.  
  71.     if (deverr & 0x8000)                        // Non-disk error
  72.         _hardretn(5);                            // Access denied
  73.  
  74.     usError = (errval & 0x00FF) + 1;        // Get error code and abort!
  75.     _hardresume(_HARDERR_FAIL);
  76.     return ;
  77. }
  78.  
  79.  
  80. //----------------------------------------------------------------------------
  81. //   Description:    Install critical error handler.
  82. //    Parameters:
  83. //       Returns:    
  84. //----------------------------------------------------------------------------
  85. VOID FN_E CritErrInitialize(void)
  86. {
  87.     if (oldint24 == NULL)
  88.         {
  89.        oldint24 = _dos_getvect(0x24);
  90.         _harderr(CritErrHandler);
  91.         BaseExitFunc((PFNEXIT)CritErrTerminate, SYS_EXIT_PRIORITY);
  92.         }
  93.     return ;
  94. }
  95.  
  96.  
  97. //----------------------------------------------------------------------------
  98. //   Description:    Remove critical error handler.
  99. //    Parameters:
  100. //       Returns:
  101. //----------------------------------------------------------------------------
  102. VOID FN_E CritErrTerminate(void)
  103. {
  104.     if (oldint24 && oldint24 == _dos_getvect(0x24)) 
  105.        _dos_setvect(0x24,oldint24);
  106.  
  107.     oldint24 = NULL;
  108.     return ;
  109. }
  110.  
  111. #endif                                            // #if OS_DOS && COMPILER_BORLAND
  112.  
  113.  
  114. //----------------------------------------------------------------------------
  115. //   Description:    Return critical error handler code.
  116. //    Parameters:
  117. //       Returns:    Error code.
  118. //                       1  Write protect
  119. //                       2  Unknown unit
  120. //                       3  Drive not ready
  121. //                       4  Unknown command
  122. //                       5  Data error (CRC)
  123. //                       6  Bad request
  124. //                       7  Seek error
  125. //                       8  Unknown media type
  126. //                       9  Sector not found
  127. //                       10 Printer out of paper
  128. //                       11 Write fault
  129. //                       12 Read fault
  130. //                       13 General failure
  131. //                       14 Reserved
  132. //                       15 Reserved
  133. //                       16 Invalid disk change
  134. //----------------------------------------------------------------------------
  135. USHORT FN_E CritErr(void)
  136. {
  137.     return usError;
  138. }
  139.  
  140.  
  141. //----------------------------------------------------------------------------
  142. //   Description:    Reset critical error handler flag
  143. //    Parameters:
  144. //       Returns:    
  145. //----------------------------------------------------------------------------
  146. VOID FN_E CritErrReset(void)
  147. {
  148.     usError = 0;
  149.     errno = 0;                                    // Also reset errno
  150.     return ;
  151. }
  152.  
  153.  
  154. //----------------------------------------------------------------------------
  155. //   Description:    Run standard test suite
  156. //    Parameters:    sTest        Test to run.
  157. //                                        0        Run all default tests (except).
  158. //       Returns:    TRUE if successful.
  159. //----------------------------------------------------------------------------
  160. #if COMPILE_TEST
  161. BOOL FN CritErrTest(SHORT sTest)
  162. {
  163.     NOTUSED(sTest);
  164. #if OS_DOS && COMPILER_BORLAND
  165.  
  166.     KbdFlush();
  167.     Output("Critical error handler enabled.\nOpen the door of drive A:\n");
  168.     while (!KbdReady())
  169.         ;
  170.  
  171.     KbdChar();
  172.  
  173.     CritErrReset();
  174.    Output("fopen() returned %p\n", fopen("A:temp.dat", "w"));
  175.     Output("Critical error code is %ld\n", (LONG)CritErr());
  176.  
  177. #else
  178.     Output("This test is only valid under DOS\n");
  179. #endif
  180.     return TRUE;
  181. }
  182. #endif
  183. //----------------------------------------------------------------------------
  184. //------------------------------- End of File --------------------------------
  185. //----------------------------------------------------------------------------
  186.